#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import models
import os
import sys
import django

sys.path.append(r"web")
sys.path.append(r"algorithm")
sys.path.append(r"cta")

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'adam3.settings')
django.setup()


class ConceptBoardIndex(models.Model):
    """
    概念板块指数
    """

    # 主键
    id = models.AutoField(primary_key=True)

    # 名称
    name = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # myquant代码
    myquant_code = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # akshare代码
    akshare_code = models.CharField(max_length=32, db_index=True, null=True, blank=True)

    # 日期
    transaction_date = models.DateTimeField(null=True, db_index=True, blank=True)

    # 开盘价
    open_price = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 收盘价
    close_price = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 最高价
    highest_price = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 最低价
    lowest_price = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 上一个交易日的收盘价
    last_close_price = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 涨跌幅。单位：%
    change_range = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 涨跌额
    change_amount = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 成交量
    turnover = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 成交额
    volume = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 振幅
    amplitude = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    # 换手率。单位：%
    turnover_rate = models.DecimalField(max_digits=32, decimal_places=16, null=True, blank=True)

    class Meta:
        managed = True
        db_table = 'CONCEPT_BOARD_INDEX'
        verbose_name = '概念板块指数'
        verbose_name_plural = verbose_name
        # 单列索引
        # indexes = [
        #     models.Index(fields=['code']),
        #     models.Index(fields=['k_line_period_type']),
        #     models.Index(fields=['begin_time']),
        #     models.Index(fields=['end_time']),
        #     models.Index(fields=['name']),
        # ]
        # 联合索引
        # index_together = [('id')]
